package gov.kqqzyyy.monkey.orderpad.network;

import java.util.List;
import java.util.concurrent.TimeUnit;

import gov.kqqzyyy.monkey.orderpad.network.bean.BaseResponse;
import gov.kqqzyyy.monkey.orderpad.network.config.HttpConfig;
import gov.kqqzyyy.monkey.orderpad.object.DC_KWBZ;
import gov.kqqzyyy.monkey.orderpad.object.DD_DDMX;
import gov.kqqzyyy.monkey.orderpad.object.FloorPatient;
import gov.kqqzyyy.monkey.orderpad.object.FloorsAndBeds;
import gov.kqqzyyy.monkey.orderpad.object.MRCPXX;
import gov.kqqzyyy.monkey.orderpad.object.Patient_JRHC;
import gov.kqqzyyy.monkey.orderpad.object.XTGL;
import gov.kqqzyyy.monkey.orderpad.object.post_param.CancelOrder_Param;
import gov.kqqzyyy.monkey.orderpad.object.post_param.StoredOrder;
import gov.kqqzyyy.monkey.orderpad.object.post_param.UserLoginParam;
import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class RetrofitUtil {

    private static RetrofitUtil mRetrofitUtil;
    private final ApiInterface mApiInterface;

    private RetrofitUtil() {
        OkHttpClient mOkHttpClient = new OkHttpClient.Builder()
                .connectTimeout(HttpConfig.CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(HttpConfig.READ_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(HttpConfig.WRITE_TIMEOUT, TimeUnit.SECONDS)
                .build();
        Retrofit mRetrofit = new Retrofit.Builder()
                .baseUrl(HttpConfig.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())//添加gson转换器
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//添加rxjava转换器
                .client(mOkHttpClient)
                .build();
        mApiInterface = mRetrofit.create(ApiInterface.class);
    }

    public static RetrofitUtil getInstence() {
        if (mRetrofitUtil == null) {
            synchronized (RetrofitUtil.class) {
                if (mRetrofitUtil == null)
                    mRetrofitUtil = new RetrofitUtil();
            }

        }
        return mRetrofitUtil;
    }

    public Observable<BaseResponse<String>> getSystemTime() {
        return mApiInterface.getSystemTime();
    }

    public Observable<BaseResponse<List<MRCPXX>>> getMRCP() {
        return mApiInterface.getMRCP();
    }

    public Observable<BaseResponse<List<DC_KWBZ>>> getKWBZ() {
        return mApiInterface.getKWBZ();
    }

    public Observable<BaseResponse<XTGL>> doLogin(UserLoginParam param) {
        return mApiInterface.doLogin(param);
    }

    public Observable<BaseResponse<List<FloorsAndBeds>>> getFloorsAndBeds(String param) {
        return mApiInterface.getFloorsAndBeds(param);
    }

    public Observable<BaseResponse<List<FloorPatient>>> getFloorPatients(String param) {
        return mApiInterface.getFloorPatients(param);
    }

    public Observable<BaseResponse<List<Patient_JRHC>>> getHCBR() {
        return mApiInterface.getHcxxes();
    }

    public Observable<BaseResponse<String>> doSaveOrderDish(List<StoredOrder> param) {
        return mApiInterface.saveOrderDish(param);
    }

    public Observable<BaseResponse<List<DD_DDMX>>> getPatientDCDDByZyh(String param) {
        return mApiInterface.getPatientDCDD(param);
    }

    public Observable<BaseResponse<String>> doCancelOrder(CancelOrder_Param param) {
        return mApiInterface.cancelOrder(param);
    }

    public Observable<BaseResponse<String>> doUploadImgs(RequestBody des, List<MultipartBody.Part> param) {
        return mApiInterface.doUploadImg(des, param);
    }


}
